﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack)
        {

            String Act = Page.Request.QueryString["Action"];  // Page.Request.QueryString["Action"];
            if (Act == null)
                return;
            if (Act.ToString().ToLower() == "LoginCheck".ToLower())
            {


                String AdminName = CheckClass.NoSqlHack(Request.Form["AdminName"]);
                String password = CheckClass.NoSqlHack(Request.Form["password"]);
                String Md5_Pass = CheckClass.MD5(password, 32);


                EntityOprHelper helper = new EntityOprHelper();
                AdminClass admin = helper.GetEntity<AdminClass>(AdminName);
                if (admin != null)
                {
                    if (Md5_Pass != admin.password)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('用户名密码错误');", true);
                        Response.Redirect("Admin_login.aspx");

                    }
                    else
                    {
                        Session["Admin"] = AdminName;
                        Session["AdminSession"] = true;
                        Response.Redirect("index.html");

                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('用户名不存在');", true);
                }
            }
            else if (Act == "LoginCheck")
            {
                Session["Admin"] = null;
                Session["AdminSession"] = null;
                Response.Redirect("Admin_login.aspx");
            }
        }
    }
}
